package org.example.maven.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.example.maven.entity.ActionTicket;
import org.example.maven.pojo.Result;
import org.example.maven.pojo.action.ActionListAdd;
import org.example.maven.service.ActionService;
import org.example.maven.service.ActionTicketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/action")
public class ActionController {
    @Autowired
    private ActionService actionService;
    @Autowired
    private ActionTicketService actionTicketService;

    //添加活动
    @PostMapping("/addAction")
    @PreAuthorize("permitAll()")
    public Result addAction(@RequestBody ActionListAdd actionListAdd) {
        System.out.println(actionListAdd);
        //actionService.save(actionListAdd);
        actionService.addAction(actionListAdd);
        return  Result.success("添加成功");
    }
    //查询所有活动
    @GetMapping("/getAllAction")
    @PreAuthorize("permitAll()")
    public Result getAllAction() {
        Result res=Result.success();
        res.put("data",actionService.list());
        res.put("total",actionService.count());
        return res;
    }
    //添加活动票数信息
    @PostMapping("/addActionTicket")
    @PreAuthorize("permitAll()")
    public Result addActionTicket(@RequestBody ActionTicket actionTicket) {
        System.out.println(actionTicket);
        actionTicketService.saveActionTicket(actionTicket);
        return  Result.success("添加成功");
    }
    //根据票的id获取活动票的详情信息
    @GetMapping("/getActionTicketDetailById/{id}")
    @PreAuthorize("permitAll()")
    public Result getActionTicketDetailById(@PathVariable int id) {
        //根据活动id为查询条件返回对应的票详情
        return Result.success(actionTicketService.getOne(new LambdaQueryWrapper<ActionTicket>().eq(ActionTicket::getActionId, id)));
    }

    //获取活动订单list信息
    @GetMapping("/getAllOrderList/{id}")
    @PreAuthorize("permitAll()")
    public Result getAllOrderList(@PathVariable(required = false) int id) {
        return Result.success(actionService.getAllOrderList(id));
    }
}
